/* eslint-disable prefer-template */
import program from 'commander';
import { VERSION } from './utils/constants';

let actionMap = {
  install: {
    // 配置命令的名字
    alias: 'i', // 命令的别名
    description: 'install template',
    examples: ['zf-cli i', 'zf-cli install'],
  },
  config: {
    alias: 'c',
    description: 'config .zfclirc',
    examples: [
      'zf-cli config set <key> <v>',
      'zf-cli config get <key>',
      'zf-cli config remove <key>',
    ],
  },
  '*': {
    description: 'not found',
    examples: [],
  },
};

Object.keys(actionMap).forEach((action) => {
  program
    .command(action)
    .description(actionMap[action].description)
    .alias(actionMap[action].alias)
    .action(() => {
      console.log(action);
      if (action === 'config') {
        main(action, process.argv.slice(3));
      } else if (action === 'install') {
        console.log('install');
      }
      main();
    });
});

function help() {
  console.log('\r\n  ' + 'how to use command');
  Object.keys(actionMap).forEach((action) => {
    actionMap[action].examples.forEach((example) => {
      console.log('  -' + example);
    });
  });
}

program.on('-h', help);
program.on('--help', help);
program.version(VERSION, '-v --version').parse(process.argv);

console.log('hello !');
